package Thread_Test;

public class test {
    public static void main(String[] args) throws InterruptedException {
//        //自定义run接口
//        Thread t1 = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                for (int i = 0; i <= 1000; ++i) {
//                    System.out.println(Thread.currentThread().getName() + ":" + i);
//                }
//            }
//        }, "for");
//        t1.start();
//        try {
//            t1.join();
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
//        for(int i = 0; i <= 1000; ++i) {
//            System.out.println(Thread.currentThread().getName() + ":" + i);
//        }
//
//        //使用类继承Thread
//        Swim s1 = new Swim();
//        s1.start();
//        try {
//            s1.join();
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
        Ticket ticket = new Ticket();
        //多线程抢票系统
        Thread t1 = new Thread(ticket);
        Thread t2 = new Thread(ticket);
        Thread t3 = new Thread(ticket);
        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();
    }
}
